package com.gqr.threadlocal;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:ThreadLocalNormalUsage00
 * author:guqingrong
 * Date:2024-05-07 22:06
 * Description:30个线程分别用自己的SimpleDateFormat
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class ThreadLocalNormalUsage01 {
    public static void main(String[] args) throws InterruptedException {
        /**
         * 演示for循环创建出线程打印日期 结果没影响
         */
        for (int i = 0; i < 30; i++) {
            int finalI = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String date = new ThreadLocalNormalUsage01().date(finalI);
                    System.out.println(date);
                }
            }).start();
            Thread.sleep(100);
        }


    }

    public String date(int seconds) {
        // 参数的单位是毫秒,从1970年01月01日 00:00:00 GMT计时
        Date date = new Date(1000L * seconds);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return dateFormat.format(date);
    }
}
